package com.javasm.dict.service.impl;


import com.javasm.dict.dao.DicDataDao;
import com.javasm.dict.entity.SysDicData;
import com.javasm.dict.service.DicDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DicDataServiceImpl implements DicDataService {
    @Resource
    private DicDataDao ddd;
    //传入dictType(字典类型) 返回字典项map
    @Override
    public Map<String, String> mapByDictTypeKeyIsEntryTag(String dictType) {
        List<SysDicData> dictEntries = this.listByDictType(dictType); //订单状态
        Map<String,String> dictEntryMap = new HashMap<>();
        for (SysDicData dictEntry : dictEntries) {
            dictEntryMap.put(dictEntry.getDicDataLabel(),dictEntry.getDicDataVal()+"");
        }
        return dictEntryMap;
    }

    @Override
    public Map<String, String> mapByDictTypeKeyIsEntryValue(String dictType) {
        List<SysDicData> dictEntries = listByDictType(dictType); //订单状态
        Map<String,String> dictEntryMap = new HashMap<>();
        for (SysDicData dictEntry : dictEntries) {
            dictEntryMap.put(dictEntry.getDicDataVal().toString(),dictEntry.getDicDataLabel());
        }
        return dictEntryMap;
    }

    List<SysDicData> listByDictType(String type){
        SysDicData d = new SysDicData();
        d.setDicType(type);
        List<SysDicData> list = this.getList(d);
        return list;
    }

    @Override
    public List<SysDicData> getList(SysDicData dicData) {
        return ddd.getList(dicData);
    }

    @Override
    public boolean insertAll(SysDicData dicData) {
        int i = ddd.insertAll(dicData);
        return i==1;
    }

    @Override
    public boolean update(SysDicData dicData) {
        int update = ddd.update(dicData);
        return update ==1;
    }

    @Override
    public boolean delByIds(String[] ids) {
        int delete = ddd.delete(ids);
        return delete==ids.length;
    }

}
